home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / instr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  6.7 KB  |  229 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    instr
  24. #undef    innstr
  25. #undef    winstr
  26. #undef    winnstr
  27. #undef    mvinstr
  28. #undef    mvinnstr
  29. #undef    mvwinstr
  30. #undef    mvwinnstr
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    move
  35. #  undef    wmove
  36. #  undef    inch
  37. #  undef    winch
  38. #  undef    mvwinch
  39. #endif
  40.  
  41. #ifdef PDCDEBUG
  42. char *rcsid_instr  = "$Id$";
  43. #endif
  44.  
  45. /*man-start*********************************************************************
  46.  
  47.   Name:                                                        instr
  48.  
  49.   Synopsis:
  50.       int instr(char *str);
  51.       int innstr(char *str, int n);
  52.       int winstr(WINDOW *win, char *str);
  53.       int winnstr(WINDOW *win, char *str, int n);
  54.       int mvinstr(int y, int x, char *str);
  55.       int mvinnstr(int y, int x, char *str, int n);
  56.       int mvwinstr(WINDOW *, int y, int x, char *str);
  57.       int mvwinnstr(WINDOW *, int y, int x, char *str, int n);
  58.  
  59.   System V Curses Description:
  60.      These routines return a string of characters in str, starting at the
  61.      current cursor position in the named window and ending at the right
  62.      margin of the window.  Attributes are stripped from the characters.
  63.      The four functions with n as the last argument return the string at most
  64.      n characters long.
  65.  
  66.      Note:  instr(), innstr(), winstr(), mvinstr(), mvinnstr(),
  67.          mvwinstr() and mvwinnstr() are all macros.
  68.  
  69.   X/Open Return Value:
  70.      All functions return OK on success and ERR on error.
  71.  
  72.   X/Open Errors:
  73.      No errors are defined for this function.
  74.  
  75.   Portability                             X/Open    BSD    SYS V
  76.                                           Dec '88
  77.       instr                                 -        -      4.0
  78.       winstr                                -        -      4.0
  79.       mvinstr                               -        -      4.0
  80.       mvwinstr                              -        -      4.0
  81.       innstr                                -        -      4.0
  82.       winnstr                               -        -      4.0
  83.       mvinnstr                              -        -      4.0
  84.       mvwinnstr                             -        -      4.0
  85.  
  86. **man-end**********************************************************************/
  87.  
  88. /***********************************************************************/
  89. int    instr(char *str)
  90. /***********************************************************************/
  91. {
  92. #ifdef PDCDEBUG
  93.     if (trace_on) PDC_debug("instr() - called: string=\"%s\"\n",str);
  94. #endif
  95.  
  96.     if (stdscr == (WINDOW *)NULL)
  97.         return( ERR );
  98.  
  99.     return(winnstr(stdscr,str,stdscr->_maxx));
  100. }
  101. /***********************************************************************/
  102. int    innstr(char *str, int n)
  103. /***********************************************************************/
  104. {
  105. #ifdef PDCDEBUG
  106.     if (trace_on) PDC_debug("innstr() - called: n %d \n",n);
  107. #endif
  108.  
  109.     if (stdscr == (WINDOW *)NULL)
  110.         return( ERR );
  111.  
  112.     return(winnstr(stdscr,str,n));
  113. }
  114. /***********************************************************************/
  115. int    winstr(WINDOW *win, char *str)
  116. /***********************************************************************/
  117. {
  118. #ifdef PDCDEBUG
  119.     if (trace_on) PDC_debug("winstr() - called: \n");
  120. #endif
  121.  
  122.     if (win == (WINDOW *)NULL)
  123.         return( ERR );
  124.  
  125.     return(winnstr(win,str,win->_maxx));
  126. }
  127. /***********************************************************************/
  128. int    winnstr(WINDOW *win, char *str, int n)
  129. /***********************************************************************/
  130. {
  131.     chtype tmp;
  132.     int oldy = win->_cury;
  133.     int oldx = win->_curx;
  134.     int imax = (win->_maxx - win->_curx);
  135.     int ic;
  136.  
  137. #ifdef PDCDEBUG
  138.     if (trace_on) PDC_debug("winnstr() - called: n %d \n",n);
  139. #endif
  140.  
  141.     if (win == (WINDOW *)NULL)
  142.         return( ERR );
  143.  
  144.     if( n > 0 )
  145.         imax = ((imax<n)?imax:n);
  146.  
  147.     for ( ic=0; ic < imax; ic++ )
  148.     {
  149.         tmp = mvwinch( win, oldy, oldx+ic );
  150.         if( tmp == ERR ) 
  151.         {
  152.             *(str+imax) = '\0';
  153.             return( ERR );
  154.         }
  155.         *(str+ic) = tmp & A_CHARTEXT;
  156.     }
  157.  
  158.     *(str+imax) = '\0';
  159.  
  160.     win->_curx = oldx;
  161.  
  162.     return( OK );
  163. }
  164. /***********************************************************************/
  165. int    mvinstr(int y, int x, char *str)
  166. /***********************************************************************/
  167. {
  168. #ifdef PDCDEBUG
  169.     if (trace_on) PDC_debug("mvinstr() - called: y %d x %d \n",y,x);
  170. #endif
  171.  
  172.     if (stdscr == (WINDOW *)NULL)
  173.         return( ERR );
  174.  
  175.     if (move(y,x) == ERR)
  176.         return( ERR );
  177.  
  178.     return(winnstr(stdscr,str,stdscr->_maxx));
  179. }
  180. /***********************************************************************/
  181. int    mvinnstr(int y, int x, char *str, int n)
  182. /***********************************************************************/
  183. {
  184. #ifdef PDCDEBUG
  185.     if (trace_on) PDC_debug("mvinnstr() - called: y %d x %d n %d \n",y,x,n);
  186. #endif
  187.  
  188.     if (stdscr == (WINDOW *)NULL)
  189.         return( ERR );
  190.  
  191.     if (move(y,x) == ERR)
  192.         return( ERR );
  193.  
  194.     return(winnstr(stdscr,str,n));
  195. }
  196. /***********************************************************************/
  197. int    mvwinstr(WINDOW *win, int y, int x, char *str)
  198. /***********************************************************************/
  199. {
  200. #ifdef PDCDEBUG
  201.     if (trace_on) PDC_debug("mvwinstr() - called: y %d x %d \n",y,x);
  202. #endif
  203.  
  204.     if (win == (WINDOW *)NULL)
  205.         return( ERR );
  206.  
  207.     if (wmove(win,y,x) == ERR)
  208.         return( ERR );
  209.  
  210.     return(winnstr(win,str,win->_maxx));
  211. }
  212. /***********************************************************************/
  213. int    mvwinnstr(WINDOW *win,int y, int x, char *str, int n)
  214. /***********************************************************************/
  215. {
  216. #ifdef PDCDEBUG
  217.     if (trace_on) PDC_debug("mvwinnstr() - called: y %d x %d n %d \n",y,x,n);
  218. #endif
  219.  
  220.     if (win == (WINDOW *)NULL)
  221.         return( ERR );
  222.  
  223.     if (wmove(win,y,x) == ERR)
  224.         return( ERR );
  225.  
  226.     return(winnstr(win,str,n));
  227. }
  228.